<!-- 重置密码组件 -->
<template>
    <div class="resetPassword">
        <a-form-model :rules="rules" ref="ruleForm" :model="formPassword">
            <a-form-model-item prop="password">
                <a-input-password v-model="formPassword.password" placeholder="请输入密码">

                </a-input-password>
            </a-form-model-item>
            <a-form-model-item prop="confirmPassword">
                <a-input-password v-model="formPassword.confirmPassword" placeholder="请确认密码" >

                </a-input-password>
            </a-form-model-item>
        </a-form-model>
    </div>
</template>

<script >
export default {
    name: "resetPassword",
    data() {
        let validatePass = (rule, value, callback) => {
            if (value === '') {
                callback(new Error('请确认密码'));
            } else if (value !== this.formPassword.password) {
                callback(new Error("两次输入的密码不一致"));
            } else {
                callback();
            }
        };
        return {
            formPassword: {
                password: '',
                confirmPassword: ''
            },

            rules: {
                password: [
                    { required: true, message: '请输入密码', trigger: 'change' },
                    {
                        pattern: '^[a-zA-Z0-9]*$',
                        message: '密码长度为8-20个字符，需包含大小写字母和数字'
                    }
                ],
                confirmPassword: [
                    { validator: validatePass, trigger: 'change' }
                ]
            }
        }
    },
    mounted() {},
    methods: {

        onSubmit() {
            this.$refs.ruleForm.validate(valid => {
                if (valid) {
                    this.$emit('validatePassword', this.formPassword)
                } else {
                    this.$emit('validatePassword', false)
                    return false;
                }
            });
        },
        // confirmChange(e) {
        //     let val = e.target.value
        //     console.log(val);
        // }
        // getVerCode() {
        //     this.$refs.ruleForm.validateField('phoneNum', valid => {
        //         if (valid) {

        //         } else {

        //         }
        //     });
        // },

    }
}
</script>

<style scoped>
.resetPassword {
    width: 305px;
}
</style>
